<template>
	<view class="study">
		<view class="avater">
			<image :src="info.avatar ?  info.avatar+'?v=55' : '../../static/defaultAvatar.png'"></image>
			<view class="avaterInfo">
				<view class="avaterName">{{ info.nick_name ?  info.nick_name : '请登录' }}</view>
				<text class="avaterArea">{{ info.nick_name ?  "地区:"+info.area : '' }}</text>
			</view>
		</view>
		<!-- 	<view class="top">
			本周尚未开始学习>
		</view>
		<view class="top" style="margin-top: 10px;">
			所属公司：{{ info.work }}
		</view> -->
		<view class="bottom">
			已加入 {{ 1 }}, 累计学习{{ info.total_hour }}小时
		</view>
	</view>
	<view>
		<!-- <uni-segmented-control :current="current" :values="items" @clickItem="onClickItem" styleType="text"
			activeColor="#3476f0"></uni-segmented-control> -->
		<view class="content">
			<view class="propject-title">学习项目</view>
			<block v-if="list.length>0">
				<view class="card" v-for="item in list" :key="item" @click="toDetial(item.id)" v-if="list.length !== 0">
					<view class="left">
						<!-- <view class="type">
						{{ "课程" }}
					</view> -->
						<image :src="item.thumb" mode=""></image>
					</view>
					<view class="right">
						<text>{{ item.title }}</text>
						<br>
						<text class="info">{{ item.content }}</text>
						<!-- <view class="bottom">
						<view class="botLeft">
							发布日期：<br />{{ item.publish_date }}
						</view>
						
					</view> -->
						<view style="color: #999999;" v-if="item.progress=='0.00'" class="bottom">学习进度:<text
								style="font-weight: 600;color: #dd3621;flex:5">未开始</text></view>
						<view style="color: #999999;" v-else class="bottom">学习进度:<text
								style="font-weight: 600;color: #dd3621;flex:5">{{item.progress * 100}}%</text></view>
					</view>
				</view>
			</block>
			<block v-else>
				<view style="color: red;padding-left: 10rpx;">您未加入任何学习项目</view>
				<image src="@/static/without.png" style="width: 100%;"></image>
			</block>
		</view>
	</view>
</template>

<script>
	import {
		project,
		center
	} from '@/api/study.js';
	import {
		mixin
	} from '@/static/mixin.js'
	export default {
		mixins: [mixin],
		created() {
			let that = this;
			project().then(res => {
				that.list = res.list;
			})
			center().then(res => {
				that.info = res;
			})
		},
		onShow() {
			let that = this;
			project().then(res => {
				that.list = res.list;
			})
			center().then(res => {
				that.info = res;
			})
		},
		data() {
			return {
				list: [],
				items: ['学习项目'],
				current: 0,
				active: 0,
				info: {},
			};
		},
		methods: {
			toDetial(id) {
				console.log("项目id", id);
				uni.navigateTo({
					url: `/pages/study/detail/index?id=${id}`
				})
			},
			onClickItem(e) {
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
			},
			group(val) {
				this.active = val;
			},
			Class(val) {
				this.active = val;
			},
		}
	};
</script>

<style scoped lang="scss">
	@import '../../static/font.scss';

	.card {
		background-color: #fff;
		display: flex;
		box-sizing: border-box;
		margin: 10px;
		border-radius: 10px;
		overflow: hidden;
		height: 130px;

		.left {
			width: 50%;
			height: 100%;
			position: relative;

			.type {
				position: absolute;
				right: 10px;
				top: 10px;
				padding: 3px;
				color: $uni-text-color-white;
				background-color: rgba(0, 0, 0, 0.6);
				border-radius: 5px;
				font-size: 14px;
			}

			image {
				width: 100%;
				height: 100%;
			}
		}

		.right {
			width: 50%;
			padding: 10px;
			position: relative;

			text {
				font-size: $uni-text-size-md;
			}

			.info {
				margin-top: 20rpx;
				color: $uni-text-color-grey;
				font-size: 14px;
				display: inline-block;
				white-space: nowrap;
				width: 100%;
				overflow: hidden;
				text-overflow: ellipsis;
			}

			.bottom {
				view {
					color: $uni-text-color-grey;
					font-size: 14px;
				}

				.botLeft {
					color: $uni-text-color-grey;
					font-size: 13px;
				}

				font-size: 14px;
				text{
					font-size: 14px;
				}
				width: 80%;
				position: absolute;
				bottom: 10px;
				display: flex;
				justify-content: space-between;
				align-items: center;
			}
		}
	}

	.study {
		background: linear-gradient(to bottom, $uni-color-primary 10%, $uni-bg-color-grey 100%);

		.avater {
			display: flex;
			// justify-content: space-between;
			align-items: center;
			padding-top: 20px;

			image {
				width: 80px;
				height: 80px;
				border-radius: 50%;
				vertical-align: middle;
				margin: 20px;
				margin-right: 10px;
			}

			.avaterInfo {
				display: flex;
				justify-content: space-between;
				flex-direction: column;
				align-items: center;
				text-align: left;

				.avaterArea {}

				.avaterName {
					width: 100%;
					text-align: left;
					font-size: 24px;
					font-weight: 500;
				}
			}

			// .right {
			// 	display: flex;
			// 	align-items: center;
			// 	justify-content: center;
			// 	font-size: 14px;
			// 	color: $uni-text-color;
			// 	height: 40px;
			// 	background-color: #5b81c8;
			// 	width: 100px;
			// 	border-top-left-radius: 50px;
			// 	border-bottom-left-radius: 50px;
			// }
		}

		.top {
			margin-left: 20px;
			font-size: 16px;
			opacity: 0.7;
		}

		.bottom {
			margin-left: 20px;
			margin-top: 10px;
			font-size: 16px;
			opacity: 0.7;
		}

		margin-bottom: 20px;
	}

	:deep(.segmented-control__item) {
		flex: none;
		margin-left: 20px;
	}

	:deep(.segmented-control__item.data-v-86aa1171) {
		flex: none;
		margin-left: 20px;
	}

	.content {
		margin-top: 5px;
		margin-left: 20rpx;
		margin-right: 20rpx;
		padding-top: 20rpx;

		// border-top: solid #e2e2df 2px;
		.propject-title {
			width: 120rpx;
			height: 50rpx;
			border-bottom: 4rpx solid #017bff;
			margin-bottom: 40rpx;
		}
	}

	.active {
		color: $uni-color-primary;
	}

	.classType {
		text {
			margin-left: 10px;
			margin-right: 10px;
		}
	}
</style>
